﻿#include "LicenseWindow.h"
#include "ui_LicenseWindow.h"
#include <QClipboard>
#include <QMessageBox>

LicenseWindow::LicenseWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::LicenseWindow)
{
    ui->setupUi(this);
}

LicenseWindow::~LicenseWindow()
{
    delete ui;
}

///
/// \brief LicenseWindow::openLicenseSlot
/// 接收登录打开授权界面的信号
void LicenseWindow::openLicenseSlot(LicenseCodeManagement* licenseCodeMGT)
{
    this->show();
    m_pLicenseCodeMGT = licenseCodeMGT;
    ui->leMachineCode->setText(m_pLicenseCodeMGT->getMachineCode());
    emit openLicenseSuccessSignal();
}

///
/// \brief LicenseWindow::on_pbCopy_clicked
/// 复制机器码
void LicenseWindow::on_pbCopy_clicked()
{
    QClipboard *clipboard=QApplication::clipboard();
    clipboard->setText(ui->leMachineCode->text());
}

///
/// \brief LicenseWindow::on_pbConfirm_clicked
/// 授权码验证
void LicenseWindow::on_pbConfirm_clicked()
{
    if(ui->leLicenseCode->text()==""){
        QMessageBox::information(this,"授权提示","授权码错误，请重新输入");
        return;
    }
    m_pLicenseCodeMGT->licenseValidate(ui->leLicenseCode->text(),1);
    if( m_pLicenseCodeMGT->getResultCode() == SUCCESS){
        //获取机型id信息，并发出跳转主界面的信号
        m_PlaneTypeIDStr = m_pLicenseCodeMGT->getPlaneTypeID();
        qDebug()<<"License Success. str is: "<<m_PlaneTypeIDStr<<endl;
        emit openICDSingal();
    }
}

///
/// \brief LicenseWindow::on_pbCancle_clicked
/// 取消：关闭窗口
void LicenseWindow::on_pbCancle_clicked()
{
    this->close();
}
